package com.itboye.mengwu.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.itboye.config.GlobalConfig;
import com.itboye.core.utils.XImageLoader;
import com.itboye.mengwu.R;

import java.util.List;

/** GirdView 数据适配器 */
public class ImageViewAdapter extends BaseAdapter {
	Context context;

	List<String> list;

	public ImageViewAdapter(Context _context, List<String> _list) {
		this.list = _list;
		this.context = _context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView==null) {
			viewHolder=new ViewHolder();
			LayoutInflater layoutInflater = LayoutInflater.from(context);
			convertView = layoutInflater.inflate(R.layout.item_image, null);
			viewHolder.icon= (ImageView) convertView.findViewById(R.id.icon);
			convertView.setTag(viewHolder);
		}else{
			viewHolder= (ViewHolder) convertView.getTag();
		}
		XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="+list.get(position),viewHolder.icon);
		return convertView;
	}

	static class ViewHolder {
		ImageView icon;
	}
}